<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<!-- Casting SPELs in Lisp - Emacs Lisp Edition, a Comic Book
     Written by Conrad Barski, M.D., http://lisperati.com
     Edited by James A. Webb, http://uberkode.com -->

<head>

  <title>Casting SPELs in Lisp (22)</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="author" content="James A. Webb" />
  <meta name="date" content="2007-09-016T00:00:00+00:00" />
  <meta name="keywords" content="Emacs, Lisp" />

</head>

<body>

<center>

<table cellspacing="10" width="500">
  <tr >
    <td bgcolor="#AAFFAA" height="50" align="center">
        <b>Casting SPELs</b>
    </td>
  </tr>
  <tr>
    <td>
      Now we're going to learn an incredibly powerful feature of
      Lisp: Creating SPELs!
    </td>
  </tr>
  <tr>
    <td>
      SPEL is short for "Semantic Program Enhancement Logic" and lets
      us create new behavior inside the world of our computer code
      that changes the Lisp language at a fundamental level in order
      to customize its behavior for our needs- It's the part of Lisp
      that looks most like magic. To enable SPELs, we first need to
      activate SPELs inside our Lisp interpreter (Don't worry about
      what this line does - advanced Lispers should read my short
      <a href="casting-spels-emacs-33.html" >essay</a>.)
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkblue">
  (defmacro defspel (&amp;rest rest) `(defmacro ,@rest))
</pre>
    </td>
  </tr>
  <tr>
    <td>
      Ok, now that they're enabled, let's cast our first spell,
      called <tt>walk</tt>:
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkblue">
  (defspel walk (direction)
    `(walk-direction ',direction))
</pre>
    </td>
  </tr>
  <tr>
    <td>
      What this code does is it tells the Lisp interpreter that the
      word <tt>walk</tt> is not actually the word <tt>walk</tt> but
      the word <tt>walk-direction</tt> and that the word
      <tt>direction</tt> actually has a quote in front of it, even
      though we can't see it. Basically we can sneak in some special
      code inbetween our program and the interpreter that changes our
      code into something else before it is interpreted.
    </td>
  </tr>
  <tr>
    <td align="center">
      &lt;&lt; <a href="casting-spels-emacs-1.html">begin</a>
      &lt; <a href="casting-spels-emacs-21.html">previous</a> - 
      <a href="casting-spels-emacs-23.html">next</a> &gt;
      <a href="casting-spels-emacs-35.html" >end</a> &gt;&gt;
    </td>
  </tr>
</table>

</center>

</body>

</html>